Public Class ctlAdvantageEditor

    Private adv(5) As Label
    Private edit(5) As Button
    Private ptrBG As cmplib01.BattlegroupChit


    Private Sub ctlAdvantageEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    End Sub


    Private Sub initLabels()
        adv(0) = a0
        adv(1) = a1
        adv(2) = a2
        adv(3) = a3
        adv(4) = a4
        adv(5) = a5

        edit(0) = btnedit0
        edit(1) = btnedit1
        edit(2) = btnedit2
        edit(3) = btnedit3
        edit(4) = btnedit4
        edit(5) = btnedit5

        For i As Byte = 0 To edit.GetUpperBound(0)
            edit(i).Tag = i
        Next
    End Sub

    Public Sub ListAdvantages(ByRef bg As cmplib01.BattlegroupChit)
        Try
            ptrBG = bg

            initLabels()

            If ptrBG.Advantages Is Nothing Then
                ReDim ptrBG.Advantages(5)
                For i As Integer = 0 To 5
                    ptrBG.Advantages(i) = New cmplib01.Advantage
                Next
            End If

            With ptrBG
                For i As Integer = 0 To .Advantages.GetUpperBound(0)
                    If Not .Advantages(i) Is Nothing Then
                        adv(i).Text = .Advantages(i).name
                    End If
                Next
            End With

            For i As Integer = 0 To ptrBG.Advantages.GetUpperBound(0)
                adv(i).Text = ptrBG.Advantages(i).name
            Next
        Catch ex As Exception
            HandleException("frmAdvantageEditor", ex)
        End Try
    End Sub


    Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit0.Click, btnedit1.Click, btnedit2.Click, btnedit3.Click, btnedit4.Click, btnedit5.Click
        '// we have the index of the item in the sender's tag
        Try
            Dim f As New frmAdvantage
            f.showdialog(ptrBG.Advantages(DirectCast(sender, Button).Tag))
            ListAdvantages(ptrBG)

        Catch ex As Exception
            HandleException("frmAdvantageEditor", ex)
        End Try
    End Sub
End Class
